#include <iostream>
#include <cstring>
using namespace std;
//-----类的定义
class Position
{
private:
  int x, y;

public:
  Position(int x0 = 0, int y0 = 0)
  {
    x = x0;
    y = y0;
  }
  void show()
  {
    cout << x << " " << y;
  }
  ~Position()
  {
    cout << "Deconstructor of Postion---" << x << " " << y << endl;
  }
};

class Button
{
private:
  Position a; //内嵌一个对象
  char name[20];

public:
  Button(char *name, int x0, int y0) : a(x0, y0) //构造函数，初始化内嵌对象
  {
    strcpy(this->name, name); //初始化派生类的成员
  }
  void show()
  {
    cout << name << endl;
    cout << "position";
    a.show();
  }
  ~Button() { cout << "deconstructor of Button---" << name << endl; }
};

class Window
{
private:
  char name[30];
  Position a;
  int width, height;

public:
  Window(char *name, int x0, int y0, int w, int h) : a(x0, y0)
  {
    strcpy(this->name, name);
    width = w;
    height = h;
  };
  void show()
  {
    cout << name << endl;
    cout << "Position";
    a.show();
  }
  ~Window() { cout << "Deconstructor of Window---" << name << endl; }
};

class Dialogue : public Window //-----派生类，公有继承windows
{
private:
  char text[50];
  Button btn1;

public:
  Dialogue(char *name, int x0, int y0, int w, int h,        //参数总表，基类需要的参数
           char *namebtn, int xbtn, int ybtn,//参数总表，内前对象需要的参数
            char *text) : //参数总表，派生类需要的参数
                                                            Window(name, x0, y0, w, h),
                                                            btn1(namebtn, xbtn, ybtn) //初始化基类和内嵌对象
  {
    strcpy(this->text, text); //初始化派生类的成员
  }
  void show()
  {
    Window::show();
    cout << "\nText" << text << endl;
    cout << "Button";
    btn1.show();
  }
  ~Dialogue() { cout << "deconstructor of Dialogue---" << text << endl; }
};

//-----------主函数
int main()
{
  //窗口名称叫 dialogue windows demo
  //位置 10,10 宽20高30
  //对话框中有OK按钮，位置10,20
  //对话框中显示'dream..'
  Dialogue dlg1("Dialogue Window Demo", 10, 10, 20, 30, "OK", 10, 20, "dream...");
  dlg1.show();
  cout << endl;
  return 0;
}